package job;

import java.io.File;

//给指定目录下添加子目录

public class FileHandle {
    public static void main(String[] args) {
        String path = "D:\\table\\兼职\\G2内容";
//        String path ="D:\\table\\java\\Test_FileHandle";
        File file = new File(path);
        File[] files = file.listFiles();
        if (files != null) {
            for (File f : files) {
                if (f.isDirectory()) {
                    System.out.println("f="+f);
                    int leng = countFoldersInDirectory(f);
                    System.out.println(leng);
                    if(leng==0){
                        System.out.println("111111111");
                        for(int i=0 ;i<2;i++){
                            if (i==0){
                                //创建文件对象，指定父目录
                                File file1 = new File(f,"奇数");
                                file1.mkdir();
                            }else {
                                File file1 = new File(f,"偶数");
                                file1.mkdir();
                            }
                        }
                    }
                }
            }
        }

    }
    public static int countFoldersInDirectory(File dir) {
        int count = 0;
        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    count++; // 计数文件夹
                    count += countFoldersInDirectory(file); // 递归统计子目录的文件夹
                }
            }
        }
        return count;
    }
}
